package com.wangzh.king.utils;

import com.wangzh.king.Exception.KingReflectionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 反射相关工具类
 * User: wangzh
 * Date: 2016/8/25
 * Time: 14:25
 */
public class ReflectionUtils {

    private static Logger logger = LoggerFactory.getLogger(ReflectionUtils.class);

    private ReflectionUtils(){}

    /**
     * 反射生成对象
     * @param cls
     * @return
     */
    public static Object newObj(Class<?> cls){
        Object obj = null;
        try {
            obj  = cls.newInstance();
        } catch (InstantiationException e) {
            logger.error("生成["+cls.getCanonicalName()+"]发生错误",e);
            throw new KingReflectionException(e);
        } catch (IllegalAccessException e) {
            logger.error("生成[" + cls.getCanonicalName() + "]发生错误", e);
            throw new KingReflectionException(e);
        }
        return obj;
    }
}
